package com.wanxi.test;

import java.util.Random;
import java.util.Scanner;

public class Tool {
    public static int avgArray(int[] arr, int max, int min) {
        int sum = sumArray(arr);
//        for (int i = 0; i < arr.length; i++) {
//            sum += arr[i];
//        }
        return (sum - max - min) / (arr.length - 2);
    }

    /**
     * 对数组的求和
     *
     * @param arr
     * @return
     */
    public static int sumArray(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    public static int minArray(int[] arr) {
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            min = min < arr[i] ? min : arr[i];
        }
        return min;
    }

    public static int maxArray(int[] arr) {
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            max = max > arr[i] ? max : arr[i];
        }
        return max;
    }

    /**
     * @return
     */
    public static int getScannerInt(String str) {
        Scanner scanner = new Scanner(System.in);
        System.out.println(str);
        return scanner.nextInt();
    }

    /**
     * 根据长度定义数组
     *
     * @param length
     * @return
     */
    public static int[] createArray(int length) {
        int[] arr = new int[length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = getRandom(10, 20);
        }
        return arr;
    }

    /**
     * 得到start到end之间的随机数[start,end]
     *
     * @param start
     * @param end
     * @return
     */
    public static int getRandom(int start, int end) {
        Random random = new Random();

        return random.nextInt(end - start) + start;
    }
}
